package good

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"homepage_srv/homepageclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodDetailLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodDetailLogic {
	return &GoodDetailLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 商品详情
func (l *GoodDetailLogic) GoodDetail(req *types.GoodDetailRequest) (resp *types.Response, err error) {
	goodDetail, err := l.svcCtx.HomepageGrpc.GoodDetail(l.ctx, &homepageclient.GoodDetailRequest{
		Id: uint64(req.Id),
	})

	if err != nil {
		return respons.Error(400, "服务端错误", err.Error()), err
	}

	return respons.Success(goodDetail), nil
}
